package com.labichaoka.chaoka.ui.splash;

import com.labichaoka.chaoka.entity.BaseResponse;
import com.labichaoka.chaoka.entity.VersionCheckResponse;

/**
 * Created by ruan on 2018/6/4.
 */

public class SplashPresenterImpl implements SplashPresenter, SplashInteractor.OnCheckUpdateFinishedListener{
    private SplashView splashView;
    private SplashInteractor splashInteractor;
    //private UploadUtil uploadUtil;
    private Boolean locationPass=false;//位置
    private Boolean contactPass=false;//通讯录

    public SplashPresenterImpl(SplashView view, SplashInteractor interactor) {
        this.splashView = view;
        this.splashInteractor = interactor;
        //uploadUtil=new UploadUtil();

    }

    //有更新
    @Override
    public void onHasUpdate(VersionCheckResponse response) {
        splashView.hideProgress();
        splashView.update(response);
    }

    //无更新
    @Override
    public void onNoUpdate() {
        splashView.hideProgress();
        splashView.noUpdate();
    }

    @Override
    public void onFailed() {
        splashView.hideProgress();
    }

    @Override
    public void onUploadContactListSuccess(BaseResponse response) {

    }

    @Override
    public void onUploadContactListFailed() {

    }

    @Override
    public void checkUpdate(String versionId) {
        if (splashView != null) {
            splashView.showProgress();
        }
        splashInteractor.checkUpdate(versionId, this);
    }

    @Override
    public void onDestroy() {
        splashView = null;
    }

    @Override
    public void getContactList() {

        //获取通讯录权限
//        act.checkPermission(new PermissionActivity.CheckPermListener() {
//            @Override
//            public void Granted() {
//                List<ContactBean> mContactsBeanList=uploadUtil.getPhoneContacts();
//                if(mContactsBeanList.size()==0){
//                    contactPass=false;
//                    splashView.showMessage("请允许蜡笔超卡获取通讯录权限!");
//                    return;
//                }
//                contactPass=true;
//                checkUpdate(locationPass,contactPass);
//                //保存通讯录
//
//            }
//
//            @Override
//            public void Denied() {
//                System.exit(0);
//            }
//        }, "请求获取通讯录权限", Manifest.permission.READ_CONTACTS);


    }

    @Override
    public void getLocationData() {
//        act.checkPermission(new PermissionActivity.CheckPermListener() {
//            @Override
//            public void Granted() {
//                uploadUtil.getLocation();
//                uploadUtil.setCallBack(new UploadUtil.UploadCallBack() {
//                    @Override
//                    public void uploadSuccessCallBack(String str) {
//                        if(TextUtils.isEmpty(str)){
//                            locationPass=false;
//                            splashView.showMessage("请允许蜡笔超卡获取定位权限!");
//                            return ;
//
//                        }
//                        locationPass=true;
//                        splashView.showMessage(str);
//                        checkUpdate(locationPass,contactPass);
//                    }
//
//                    @Override
//                    public void uploadFailCallBack(String str) {
//
//                    }
//                });
//
//            }
//
//            @Override
//            public void Denied() {
//                System.exit(0);
//            }
//        }, "请求获取定位权限", Manifest.permission.ACCESS_COARSE_LOCATION);


    }

    //检查更新
//    private void checkUpdate(boolean lp,boolean cp){
//
//        if(lp&&cp){
//            try {
//                int versionCode = MyApplication.getInstance().getPackageManager().getPackageInfo(MyApplication.mContext.getPackageName(), 0).versionCode;
//                checkUpdate(versionCode + "");
//
//            } catch (PackageManager.NameNotFoundException e) {
//                e.printStackTrace();
//            }
//        }
//
//
//    }


}
